$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/suggestions/list',
        datatype: "json",
        colModel: [
			{ label: '建议ID', name: 'id', index: "id", hidden: true, width: 110, key: true },
            { label: '会员昵称', name: 'nickName', width: 45 },
            { label: '手机号', name: 'mobileNumber', width: 35 },
            { label: '处理状态', name: 'feedbackStatusName', width: 45 },
            { label: '意见内容', name: 'suggestion'},
			{ label: '时间', name: 'createTime', width: 45 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        multiboxonly:true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.result",
            page: "page.pageNo",
            total: "page.totalPages",
            records: "page.total"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});


var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            delFlag: null,
            statusCode: null,
            nickName: null
        },
        showList: true,
        title:null,
        flag:false,
        suggestion:{suggestionImg:null}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        del: function(){
            var sugIds = getSelectedRows();
            if(sugIds == null){
                return ;
            }
            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "sys/suggestions/delete",
                    contentType: "application/json",
                    data: JSON.stringify(sugIds),
                    success: function(r){
                        if(r.code === 'success'){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.message);
                        }
                    }
                });
            });

        },
        info: function(){
            var sugId = getSelectedRow();
            if (sugId == null) {
                return;
            }

            vm.showList = false;
            vm.title = "反馈建议详情";

            vm.getSugInfo(sugId);
        },
        getSugInfo: function(sugId){
            $.get(baseURL + "sys/suggestions/info/"+sugId, function(r){

                vm.suggestion = r.suggestion;
                vm.suggestion.suggestionImg = r.suggestion.suggestionImg;
                if (r.suggestion.suggestionImg) {
                    vm.flag = true;
                }

            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'delFlag': vm.q.delFlag, 'statusCode': vm.q.statusCode, 'nickName':vm.q.nickName},
                page:page
            }).trigger("reloadGrid");
        },
        infoReload: function () {
            vm.showList = true;
        }
    }
});